﻿import com.dmotiko.general.*
import com.dmotiko.zonaoutlet.*
import mx.transitions.*;
import mx.transitions.easing.*;
import mx.utils.Delegate;

class ZOPhotoOutletViewer
extends BaseClip {
	
	/* FLA MOVIECLIPS */
	private var mcMask:MovieClip;
	private var photosTween:Tween;
	
	private var mcContainer:MovieClip;
	private var mcButtons:MovieClip;
	private var btnActive:ButtonClip;
		
	private function initClip() {
		mcContainer = this.createEmptyMovieClip("mcContainer", this.getNextHighestDepth());
		mcButtons = this.createEmptyMovieClip("mcButtons", this.getNextHighestDepth());
		mcButtons._y = mcMask._y + mcMask._height;
		mcContainer.setMask(mcMask);
	}
		
	private function refreshData() {
		// data viene de XML, es un Array de photos
		var nX:Number = 0;
		var nBtnX:Number = 0;
		for (var i:Number = 0; i < data.length; i++){
			var clip:MovieClip = mcContainer.attachMovie("ZOPhotoOutlet", "mcPhoto" + i, mcContainer.getNextHighestDepth());
			clip._x = nX;
			nX += clip._width + 15;
			clip.setData(data[i]);
			if( data.length > 1){
				var btn:MovieClip = mcButtons.attachMovie( "FLA.photoViewerBtn", "btn", i, { _x: nBtnX } );
				nBtnX += btn._width + 2;
				mcButtons._x = mcMask._x + mcMask._width - mcButtons._width - 10;
				btn.setData( clip._x );
				if ( i == 0) {
					btnActive = ButtonClip(btn);
					btn.setActive( true );
					btn.onRollOver();
				}
				btn.addEventListener(BaseClipEvent.CHANGED, Delegate.create( this, btnRelease) );
			}
		}
	}
	
	private function btnRelease( evnt ):Void {
		if ( btnActive ) btnActive.setActive(false);
		btnActive = evnt.target;
		if ( photosTween ) photosTween.stop();
		photosTween = new Tween( mcContainer, "_x", Strong.easeOut, mcContainer._x, -evnt.data, 1, true);
	}
	
}